<?php
class admin_groupModel extends baseModel{
    protected $table = 'admin_group';

    //管理组列表
    public function group_list() {
        return $this->select('','','gid desc');
    }

    //获取权限
    public function get_base_purview(){
        return ApiHook('hook_purview_admin');
    }

    //获取菜单权限
    public function get_menu_purview(){
        $index=ApiHook('hook_menu_index');
        $category=ApiHook('hook_menu_category');
        $content=ApiHook('hook_menu_content');
        $expand=ApiHook('hook_menu_expand');
        $adminuser=ApiHook('hook_menu_admin');
        $system=ApiHook('hook_menu_system');
        $list= array(
            '首页菜单'=>$index,
            '栏目菜单'=>$category,
            '内容菜单'=>$content,
            '功能菜单'=>$expand,
            '后台用户管理菜单'=>$adminuser,
            '系统管理菜单'=>$system,
        );
       
        $ext_menu=array();
        $menu_ext1=ApiHook('hook_menu_index_ext',true);
        $ext_menu[]=$menu_ext1[0];
        $menu_ext2=ApiHook('hook_menu_category_ext',true);
        $ext_menu[]=$menu_ext2[0];
        $menu_ext3=ApiHook('hook_menu_content_ext',true);
        $ext_menu[]=$menu_ext3[0];
        $menu_ext4=ApiHook('hook_menu_expand_ext',true);
        $ext_menu[]=$menu_ext4[0];
        $menu_ext5=ApiHook('hook_menu_admin_ext',true);
        $ext_menu[]=$menu_ext5[0];
        $menu_ext6=ApiHook('hook_menu_top_ext',true);
        $ext_menu[]=$menu_ext6[0];

        $ext_array=array();
        if(!empty($ext_menu)){
            foreach ($ext_menu as $value) {
                if(!empty($value)){
                    foreach ($value as $key=>$val) {
                       $ext_array[$key][]=$val;
                    }
                }
            }
        }

        $list=array_merge((array)$list,(array)$ext_array);
        $newlist=array();
        foreach ($list as $key => $value) {
            $menulist=array();
            if(!empty($value)){
                foreach ($value as $val) {
                    $menulist=array_merge($val,$menulist);
                }
            }
            $newlist[$key]=$menulist;
        }
        return $newlist;
    }

    //获取表单权限
    public function get_form_purview(){
        return api('form','form_list');
    }

    //内容模型权限
    public function get_model_purview(){
        return api('admin','model_manage_list','list_type=1');
    }

    //管理组信息
    public function info($gid) {
        return $this->find('gid='.$gid);
    }

    //获取指定管理组列表
    public function content_list($gid) {
        return $this->select('gid in('.$gid.')','','gid desc');
    }

    //添加管理组
    public function add($data)
    {
        $data['base_purview']=serialize($data['base_purview']);
        $data['menu_purview']=serialize($data['menu_purview']);
        $data['form_purview']=serialize($data['form_purview']);
        $data['model_purview']=serialize($data['model_purview']);
        return $this->insert($data);

    }
    //编辑管理组
    public function edit($data)
    {
        $condition['gid']=intval($data['gid']);
        $data['base_purview']=serialize($data['base_purview']);
        $data['menu_purview']=serialize($data['menu_purview']);
        $data['form_purview']=serialize($data['form_purview']);
        $data['model_purview']=serialize($data['model_purview']);
        return $this->update($condition,$data); 
        
    }
    //删除管理组
    public function del($gid)
    {
        //删除关联
        model('admin_relation')->relation_del($gid);
        return $this->delete('gid='.intval($gid)); 
    }

	
}